package com.ludomancy.starwave;

import java.awt.Graphics;
import java.awt.Rectangle;

import com.ludomancy.gamelib.Utils;
import com.ludomancy.gamelib.Widget;

public class InfobarWidget extends Widget
{
	private Ship selectedShip;
	private String text = null;

	public InfobarWidget(Widget parent, Rectangle area)
	{
		super(parent, area);
	}
	
	public void setSelectedShip(Ship ship)
	{
		selectedShip = ship;
		if(selectedShip != null)
		{
			text = ship.getDescription();
		}
		else
		{
			text = null;
		}
	}

	public void paint(Graphics g)
	{
		String toDraw = text;
		boolean centered = false;
		boolean small = false;
		if(toDraw == null)
		{
			if(Game.game.phase == Game.PHASE_SETUP)
			{
				// during setup, show the current goal
				if(toDraw == null)
				{
					if(!Game.EDITOR)
					{
						small = true;
						// if there is no specific goal, just show the remaining waves
						int remaining = (LevelManager.getLevelCount() - StarWaveApplet.app.level - 1);
						if(remaining > 0)
						{
							toDraw = "Wave   " + (StarWaveApplet.app.level+1) + "  of  "+LevelManager.getLevelCount();
						}
						else
						{
							toDraw = "Last wave!";
						}
						centered = true;
					}
				}
			}
			else
			if(Game.game.phase == Game.PHASE_LEVEL_LOST || Game.game.phase == Game.PHASE_MOTHERSHIP_DEATH)
			{
				toDraw = "This defense didn't work!";
				centered = true;
			}
			else
			if(Game.game.phase == Game.PHASE_LEVEL_WON)
			{
				toDraw = "Success !!";
				centered = true;
			}
		}
		
		if(toDraw != null)
		{
//			g.setColor(getTheme().getUIBackgroundColor());
//			g.fillRect(0, 0, getWidth(), getHeight());
			g.setFont(((StarwaveTheme)getTheme()).idleBarFont);
			if(small)
			{
				g.setFont(((StarwaveTheme)getTheme()).tinyFont);
			}
			g.setColor(getTheme().getDefaultTextColor());
			if(centered)
			{
				Utils.drawStringCentered(g, toDraw, getClientRect());	
			}
			else
			{
				Utils.drawMultiline(g, toDraw,getWidth()-10, 5, 5);
			}
		}
	}
}
